[20260123] BOJ / G4 / 트리 순 / 이인희 #1822
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/22856
🧭 풀이 시간
30 분
👀 체감 난이도
✏️ 문제 설명
🔍 풀이 방법
⏳ 회고
private static Map<Integer, Node> Nodes;는 낭비이다. 키의 값이 1~N까지로 정해져있으니 그냥Node[]를 썼으면 되었다.System.exit()로 하는 방법 말고도 try~catch문으로 하면 좋다. 단순하게 RuntimeException 으로 해도된다.(단, throw new RuntimeException()을 하게된다면 사실 내부적으로 모든 콜스택을 순회하여 사전정의된 로직을 수행(fillInStackTrace()) 해서 한번은 콜스택 전체 탐색이 이뤄지게된다. 따라서 만약 문제에 따라서 예외를 제어흐름의 일부로 반복해서 수행해야할 경우면 이렇게 커스텀예외로 해야함)
throw new RuntimeException(...)방식과fillInStackTrace() 오버라이딩하여 커스텀예외 만들기, 둘다 백준에서 실행시켜보았는데 각각 524ms, 512ms 로 별 차이가 안났음.